package org.rowingmanager.util
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.*;
	
	import mx.controls.Alert;
	
	public class LoginHandler
	{
		private static var LOGIN_URL:String = "http://localhost:8080/RowingManagement/user/login" ;
		public var email:String;
		public var password:String;
		
		private var urlReq:URLRequest;
		private var urlLoader:URLLoader;
		
		public var userExists:Boolean;
		public function LoginHandler(){
			userExists = false;
		}
		
		public function login():void{
		    urlReq = new URLRequest(LOGIN_URL);
			urlReq.method = "POST";
			var params:URLVariables = new URLVariables();
			//mx.controls.Alert.show(this.password+" "+this.username);
			params.email = this.email;
			params.password = this.password;
			urlReq.data = params;
			urlLoader = new URLLoader(urlReq);
			urlLoader.addEventListener(Event.COMPLETE, handleResponse);
			urlLoader.addEventListener(IOErrorEvent.IO_ERROR,handleError);
			urlLoader.load(urlReq);
		}
		
		private function handleResponse(e:Event):void{
		 /* switch(urlLoader.data){
		  	case "true": userExists = true; break;
		  	case "false": userExists = false; break;
		  	default: userExists = false;
		  	
		  }*/
		}
		
		private function handleError(e:IOErrorEvent):void{
			mx.controls.Alert.show("ERROR:"+e.toString());
		}
		
		
		

	}
}